package com.guigu.xm.lq.service.impl;

import com.guigu.xm.lq.mapper.SysMenusMapper;
import com.guigu.xm.lq.service.SysMenusService;
import com.guigu.xm.pojo.SysMenus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SysMenusServiceImpl implements SysMenusService {
    @Autowired(required = false)
    SysMenusMapper smm;
    @Override
    public Map<SysMenus, List<SysMenus>> findMenuAll(String login_id) {
        Map<SysMenus,List<SysMenus>> map=new HashMap<>();
        List<SysMenus> menuList=smm.findAllMenus(login_id);
        //首先找到父菜单，根据父菜单id，找到对应子菜单
        for (SysMenus m:menuList){
            //如果getParent_id()值等于0，就是父菜单
            if (m.getParentId()==0){
                //再次遍历集合取对应子菜单
                List<SysMenus> menus=new ArrayList<>();
                for (SysMenus m1:menuList){
                    //如果父菜单id等于getParent_id()
                    if (m.getId()==m1.getParentId()){
                        //把子菜单存入集合
                        menus.add(m1);
                    }
                }
                //m.getMenu_name()是父菜单名字  menus是子菜单
                map.put(m,menus);
            }
        }
        return map;
    }

    @Override
    public Map<SysMenus, Map<SysMenus,List<SysMenus>>> xx(String login_id) {
        List<SysMenus> menuList1=smm.findAllMenus(login_id);
        Map<SysMenus, Map<SysMenus,List<SysMenus>>> map11=new HashMap<>();
        for (SysMenus m:menuList1){
            if (m.getParentId()==0){
                Map<SysMenus, List<SysMenus>> map12=new HashMap<>();
                for (SysMenus m1:menuList1){
                    if (m.getId()==m1.getParentId()){
                        List<SysMenus> sysMenus = new ArrayList<>();
                        for (SysMenus m2:menuList1){
                            if (m1.getId()==m2.getParentId()&&m1.getParentId()!=0){
                                sysMenus.add(m2);
                            }
                        }
                        map12.put(m1,sysMenus);
                    }
                }
                map11.put(m,map12);
            }
        }
        return map11;
    }
}
